#include<vector>
using namespace std;
struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode() : val(0), left(nullptr), right(nullptr) {}
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 };

 class Solution {
public:
    vector<vector<int>> res;
    vector<vector<int>> pathSum(TreeNode* root, int target) {
        vector<int> path;
        dfs(root, target, path);
        return res;
    }
    void dfs(TreeNode* root, int target, vector<int> &path){
        if(root == NULL)return;
        path.push_back(root->val);
        target -= root->val;

        if(target == 0 && root->left == NULL && root->right == NULL){
            res.push_back(path);
        }
        dfs(root->left, target, path);
        dfs(root->right, target, path);
        path.pop_back();
    }
};